﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Pantry.Business;
using Pantry.Entity;

namespace Pantry.Web.Users
{
    public partial class PremiseDetails : System.Web.UI.Page
    {
        private PremiseBus _premiseBus;
        private Premises _premises;
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public void ButtonSaveClick(object sender,EventArgs e)
        {
            try
            {
                _premiseBus = new PremiseBus();
                _premises = new Premises();
                _premises.LocationName = "";
                _premises.KnownAs = "";
                _premises.PrimaryLocation = true;
                _premises.LocationManaged = true;
                _premises.OrgnisationId = 0;
                _premises.LocationStatus = "";
                _premises.StNetworkConectivity = true;
                _premises.LocationStatusDate = "";
                _premises.LocationType = "";
                _premises.LocationDescription = "";
                _premises.AddressLine1 = "";
                _premises.AddressLine2 = "";
                _premises.AddressLine3 = "";
                _premises.PhoneNumber = "";
                _premises.Postcode = "";
                _premises.FaxNumber = "";
                _premises.CityTown = "";
                _premises.MinicommNumber = "";
                _premises.County = "";
                _premises.IsNewShop = true;
                _premises.CountryId = 0;
                _premises.ShopFlagDate = "";
                _premises.SpecialistShop = true;
                _premises.Accreditations = "";
                _premises.JcpOffices = "";
                _premises.CateringContact = "";
                _premises.CateringType = 0;
                _premises.LocalDemographicIssue = "";
                _premises.IsNetwork = 0;
                _premises.ClientItFacilityDetails = "";
                _premises.LocalDemographicNotes = "";
                _premises.RoomAvailability = true;
                _premises.VolunteeringOpportunities = true;
                _premises.OutreachLocation = "";
                _premises.LocalHotel = "";
                _premises.TravelDetails = "";
                _premises.VisitorParkingOnsite = true;
                _premises.TravelNearestBus = "";
                _premises.VisitorParkingSpaces = 0;
                _premises.TravelNearestRail = "";
                _premises.TravelNearestAirport = "";
                _premises.VisitorParkingAlternative = "";
                _premises.HostVisits = true;
                _premises.HostingContact = "";
                _premises.RoomOnlyRate = 0;
                _premises.NegotiatedRoomOnlyRate = 0;
                _premises.BbRate = 0;
                _premises.BbNegotiatedRate = 0;
                _premises.DdRate = 0;
                _premises.DdNegotiatedRate = 0;
                _premises.RateDay = 0;
                _premises.NegotiatedRateDay = 0;
                _premises.TeaAndCoffee = "";
                _premises.Lunch = true;
                _premises.LastNegotiatedDate = "";
                _premises.ReNegotiatedOn = "";
                _premises.NoOfMeetingRoom = 0;
                _premises.PreferedStatus = "";
                _premises.MeetingRoomRatePerDay = 0;
                _premises.Codings = "";
                _premises.Comments = "";
                _premises.IsActive = true;

                if (Request.QueryString["action"]=="create")
                {
                    if (!_premiseBus.CheckNameIsExists("","",false))
                    {
                        bool result = _premiseBus.AddPremise(_premises);
                        ScriptManager.RegisterStartupScript(this, GetType(), "Key",
                                                            result
                                                                ? "showmessage('Add new premise successfully !','SUCCESS','','false')"
                                                                : "showmessage('Cannot add new premise !','ERROR','','false')",
                                                            true);
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this, GetType(), "Key", "showmessage('Premise Name is exists !','ERROR','','false')", true);
                    }
                }
                else
                {
                    if (!_premiseBus.CheckNameIsExists("","",false))
                    {
                        int id = int.Parse(Request.QueryString["id"]);
                        _premises.PremiseId = id;
                        bool result = _premiseBus.UpdatePremise(_premises);
                        ScriptManager.RegisterStartupScript(this, GetType(), "Key",
                                                            result
                                                                ? "showmessage('Update premise successfully !','SUCCESS','','false')"
                                                                : "showmessage('Cannot update premise !','ERROR','','false')",
                                                            true);
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this, GetType(), "Key", "showmessage('Premise Name is exists !','ERROR','','false')", true);
                    }
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
    }
}
